import { defineStore } from 'pinia';

export const STORE_KEY_PAGE_LEFT = 'page-left';

export interface PageLeftState {
  // 左侧边栏是否打开
  isSidebarOpen: boolean;
}

/**
 * 左侧菜单栏相关状态
 */
// export const usePageLeftStore = defineStore(STORE_KEY_PAGE_LEFT, {
//   state: (): PageLeftState => ({
//     isSidebarOpen: true,
//   }),
//   actions: {
//     setAndPersistIsSidebarOpen(isSidebarOpen: boolean) {
//       this.isSidebarOpen = isSidebarOpen;
//     },
//   },
//   cnPersist: {
//     states: {
//       isSidebarOpen: {
//         serialize: newValue => {
//           return newValue ? '1' : '0';
//         },
//         deserialize: persistedValue => {
//           return persistedValue == '1';
//         },
//       },
//     },
//   },
// });
export const usePageLeftStore = defineStore(
  STORE_KEY_PAGE_LEFT,
  () => {
    const isSidebarOpen = ref(true);
    const setAndPersistIsSidebarOpen = (isSidebarOpen_: boolean) => {
      isSidebarOpen.value = isSidebarOpen_;
    };
    return { isSidebarOpen, setAndPersistIsSidebarOpen };
  },
  {
    cnPersist: {
      states: {
        isSidebarOpen: {
          serialize: newValue => {
            return newValue ? '1' : '0';
          },
          deserialize: persistedValue => {
            return persistedValue == '1';
          },
        },
      },
    },
  },
);
